import paltter from '../../platter/carc'
Page({

  /**
   * 页面的初始数据
   */
  data: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    let car = new paltter().palette()
    let userInfo = wx.getStorageSync('userInfo')
    car.views[1].url = userInfo.avatarUrl
    car.views[2].text = userInfo.nickName
    car.views[3].url = '/static/image/1.png'
    car.views[4].text = options.title
    car.views[5].url = '/static/image/2.png'
    that.setData({
      template: car
    })
  },

  saveImg() {
    this.saveImage()
  },

  onImgOK(e) {
    var that = this
    var imagePath = e.detail.path;
    that.setData({
      imagePath: imagePath
    })
  },

  // 保存海报
  saveImage() {
    var that = this
    wx.saveImageToPhotosAlbum({
      filePath: that.data.imagePath,
      success: (res) => {
        that.setData({
          poster_hidden: true
        })
        wx.showToast({
          title: '已保存到相册',
          mask: true
        })
        setTimeout(() => {
          wx.navigateBack()
        }, 1000)
      },
      fail() {
        wx.showModal({
          title: '保存失败！',
          content: '请检查相册访问是否授权',
          success(res) {
            if (res.confirm) {
              wx.openSetting({
                success(res) {}
              })
            } else if (res.cancel) {}
          }
        })
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})